package com.hxy.modules.demo.service.impl;

import com.hxy.modules.common.common.Constant;
import com.hxy.modules.common.page.Page;
import com.hxy.modules.common.page.PageHelper;
import com.hxy.modules.common.utils.UserUtils;
import com.hxy.modules.sys.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.hxy.modules.common.utils.Utils;
import com.hxy.modules.demo.dao.BudgetaplyDao;
import com.hxy.modules.demo.entity.BudgetaplyEntity;
import com.hxy.modules.demo.service.BudgetaplyService;



@Service("budgetaplyService")
public class BudgetaplyServiceImpl implements BudgetaplyService {
	@Autowired
	private BudgetaplyDao budgetaplyDao;
	
	@Override
	public BudgetaplyEntity queryObject(String id){
		return budgetaplyDao.queryObject(id);
	}
	
	@Override
	public List<BudgetaplyEntity> queryList(Map<String, Object> map){
		return budgetaplyDao.queryList(map);
	}

    @Override
    public List<BudgetaplyEntity> queryListByBean(BudgetaplyEntity entity) {
        return budgetaplyDao.queryListByBean(entity);
    }
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return budgetaplyDao.queryTotal(map);
	}
	
	@Override
	public int save(BudgetaplyEntity budgetaply){

		UserEntity currentUser = UserUtils.getCurrentUser();
		budgetaply.setCode(Utils.getCode("D"));
		budgetaply.setStatus(Constant.ActStauts.DRAFT.getValue());
		budgetaply.setCreateId(currentUser.getId());
		budgetaply.setCreateTime(new Date());
		budgetaply.setId(Utils.uuid());
		budgetaply.setUserId(UserUtils.getCurrentUserId());
		budgetaply.setBapid(currentUser.getBapid());
		budgetaply.setBaid(currentUser.getBaid());//未改

		return budgetaplyDao.save(budgetaply);
	}
	
	@Override
	public int update(BudgetaplyEntity budgetaply){
        return budgetaplyDao.update(budgetaply);
	}
	
	@Override
	public int delete(String id){
        return budgetaplyDao.delete(id);
	}
	
	@Override
	public int deleteBatch(String[] ids){
        return budgetaplyDao.deleteBatch(ids);
	}

	@Override
	public Page<BudgetaplyEntity> findPage(BudgetaplyEntity budgetaplyEntity, int pageNum) {
		PageHelper.startPage(pageNum, Constant.pageSize);
		budgetaplyDao.queryList(budgetaplyEntity);
		return PageHelper.endPage();
	}

}
